﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineAuction.Business;
using OnlineAuction.Entity;

namespace OnlineAuction.Admin
{
    public partial class ViewActiveAuction : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserInfo"] == null
                || Request.Cookies["UserInfo"]["Role"].ToString().CompareTo("Admin") != 0)
            {
                Response.Redirect("../Home.aspx");
            }
            else if (!Page.IsPostBack)
            {
                dataBinded();
            }
        }

        private void dataBinded()
        {
            //Get all Auction
            AuctionBO bo = new AuctionBO();
            List<AuctionDTO> list = bo.GetOnlineAuctions(txtSearch.Text);
            cpUser.PageSize = 10;
            cpUser.ShowFirstLast = true;
            cpUser.DataSource = list;
            cpUser.BindToControl = grvAuction;
            grvAuction.DataSource = cpUser.DataSourcePaged;
            grvAuction.DataBind();
        }

        protected void grvAuction_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Block")
            {
                AuctionBO bo = new AuctionBO();
                bo.BlockItemAndAuction(Convert.ToInt32(e.CommandArgument.ToString()));
                dataBinded();
            }
        }

        protected void grvAuction_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void btnsearch_Click(object sender, EventArgs e)
        {
            dataBinded();
        }
    }
}